package time.code.added;

import java.time.LocalTime;

/**
 * Description: LocalTime示例
 *
 * @author code-worker
 * @date 2021/08/22 9:57
 */
public class LocalTimeDemo {

    /**
     * task: 获取当前时间
     * @date 2021/8/22 9:58
     */
    public void getCurrentTime(){
        LocalTime currentTime = LocalTime.now();
        System.out.println("当前时间为: "+currentTime);
    }

    /**
     * task: 计算两小时|两分钟|两秒之前或之后的时间
     * @date 2021/8/22 10:09
     */
    public void plusOrMinusTime(){
        LocalTime currentTime = LocalTime.now();
        LocalTime next2HourTime = currentTime.plusHours(2);
        LocalTime last2HourTime = currentTime.plusHours(-2);
        LocalTime last2HourTime2 = currentTime.minusHours(2);
        LocalTime next2MinuteTime = currentTime.plusMinutes(2);
        LocalTime next2SecondTime = currentTime.plusSeconds(2);
        System.out.println("\n当前时间的两小时后的时间: "+ next2HourTime);
        System.out.println("当前时间的两分钟后的时间: "+ next2MinuteTime);
        System.out.println("当前时间的两秒后的时间: "+ next2SecondTime);
        System.out.println("当前时间的两小时前的时间: "+ last2HourTime);
        System.out.println("当前时间的两小时前的时间: "+ last2HourTime2);
    }

    public static void main(String[] args) {
        LocalTimeDemo demo = new LocalTimeDemo();
        demo.getCurrentTime();
        demo.plusOrMinusTime();
    }

}
